var app = getApp();
//获得

var MyRequest = require("../../utils/MyRequest.js");
var Global = require("../../Global.js");

Page({
    data:{
        company:"请选择送餐区域",
        isNEW:0
    },
    onReady:function(){
        var floors = new Array();
        for(var i=0;i<99;i++){
            var str = (i+1) + "层";
            floors[i] = str;
        }
        this.setData({
            floors:floors,
            index:5
        });
    },
    bindPickerChange:function(e){
        this.setData({
            index: e.detail.value
        })
    },
    toCompany:function(){
         wx.navigateTo({
      url: '/pages/company/company'
    });
    },
    save:function(){
        var user = Global.getUserStorage();
        if(this.data.consignee == undefined || this.data.builder == undefined || this.data.phone == undefined){
            wx.showToast({
                title: '请确保信息填写完整',
                duration: 2000
            })
            return;
        }
        var addressObj = {
            action:"add",
            accountId:user.id,
            consignee:this.data.consignee,
            builderId:this.data.builder,
            detail:this.data.detail,
            phone:this.data.phone,
            floorNo:this.data.floors[this.data.index]
        }
        if(this.data.isNEW == 1){
            addressObj.action = "update";
            addressObj.id = this.data.id;
            MyRequest.MyGetWithToast("ConsigneeUpdate", this, this.addBack, addressObj);
        }else{
            MyRequest.MyGetWithToast("ConsigneeAdd", this, this.addBack, addressObj);
        }
         
        
    },bindTextAreaBlur: function(e) {
        this.setData({
            detail: e.detail.value
        })
  },
  bindConsignee: function(e) {
    this.setData({
      consignee: e.detail.value
    })
  },
  bindPhone: function(e) {
    this.setData({
      phone: e.detail.value
    })
  },
  addBack:function(result,that){
      var pages = getCurrentPages();
      var prevPage = pages[pages.length - 2];  //上一个页面
      prevPage.Presenter.init(prevPage);
      wx.navigateBack();
  },
  del:function(){
      var user = Global.getUserStorage();
      var data = {
          action:"delete",
          accountId:user.id,
          id:this.data.id
      };
      MyRequest.MyGetWithToast("ConsigneeDelete", this, this.addBack, data);
  },
  onLoad:function(options){
      var s = options.isNEW;
      this.data.isNew = options.isNEW;
      if(s == 1){
          this.setData({
              isNEW:1,
              phone:options.phone,
              consignee:options.consignee,
              builder:options.builderId,
              detail:options.detail,
              company:options.builderName,
              id:options.id
          });
      }
  }
})